﻿//-----------------------------------------------------------------------
// <copyright file="ViewModelDispatcher.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>24/01/2013</date>
//-----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using System.Windows.Threading;

namespace ConsoleHoster.Common.Utilities.Threading
{
	public class ViewModelDispatcher : IDispatcher
	{
		private readonly Dispatcher dispatcher;

		public ViewModelDispatcher(Dispatcher argDispatcher)
		{
			if (argDispatcher == null)
			{
				throw new ArgumentNullException("argDispatcher");
			}

			this.dispatcher = argDispatcher;
		}

		public bool IsInDispatcherThread()
		{
			return this.dispatcher.CheckAccess();
		}

		public Task BeginInvoke(Action argAction, DispatcherPriority argPriority)
		{
			return this.dispatcher.BeginInvoke(argAction, argPriority).Task;
		}

		public void Invoke(Action argAction, DispatcherPriority argPriority)
		{
			this.dispatcher.Invoke(argAction, argPriority);
		}
	}
}
